﻿using System;
using System.Collections.Generic;
using System.Text;
using OneMG.Phoenix.Service.Contracts;
using OneMG.Phoenix.Service.Model;
using OneMG.Phoenix.IBatisRepository;
using OneMG.Phoenix.Respository;
using System.Data;
using OneMG.Phoenix.Entity;

namespace OneMG.Phoenix.Service
{
    public class OfferService : IOfferService
    {
		 IOffer offer = new OfferRepository();
		 
        public System.Int32 AddOffer(OfferModel model)
        {
			EOffer entity = ConvertModelToEntity(model);
			
            return offer.AddOffer(entity);
        }

		public void UpdateByOfferID (OfferModel model)
		{
			EOffer entity = ConvertModelToEntity(model);

            offer.UpdateByOfferID(entity);

		}

		public void DeleteByOfferID (System.Int32 offerID)
		{
		
            offer.DeleteByOfferID(offerID);

		}
		 
        public OfferModel GetByOfferID (System.Int32 offerID)
        {
        
			EOffer entity = offer.GetByOfferID(offerID);
			
            OfferModel model = ConvertEntityToModel(entity);


            return model;
        }
        
		public OfferModel ConvertEntityToModel(EOffer entity)
		{
			if (entity == null)
            {
                return null;
            }
			OfferModel model = new OfferModel();
                        model.OfferID = entity.OfferID;
                        model.CateID = entity.CateID;
                        model.Photo = entity.Photo;
                        model.Title = entity.Title;
                        model.price = entity.Price;
                        model.Address = entity.Address;
                        model.Season = entity.Season;
                        model.NeedDays = entity.NeedDays;
                        model.Rush = entity.Rush;
                        model.Description = entity.Description;
                        model.IsShow = entity.IsShow;
                        model.IsTop = entity.IsTop;
                        model.Visitation = entity.Visitation;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        model.CreateUser = entity.CreateUser;
                        model.UpdateUser = entity.UpdateUser;
                        return model;
		}
		
		public EOffer ConvertModelToEntity(OfferModel model)
		{
			if (model == null)
            {
                return null;
            }
			EOffer entity = new EOffer();
                        entity.OfferID = model.OfferID;
                        entity.CateID = model.CateID;
                        entity.Photo = model.Photo;
                        entity.Title = model.Title;
                        entity.Price = model.price;
                        entity.Address = model.Address;
                        entity.Season = model.Season;
                        entity.NeedDays = model.NeedDays;
                        entity.Rush = model.Rush;
                        entity.Description = model.Description;
                        entity.IsShow = model.IsShow;
                        entity.IsTop = model.IsTop;
                        entity.Visitation = model.Visitation;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        entity.CreateUser = model.CreateUser;
                        entity.UpdateUser = model.UpdateUser;
                        return entity;
		}
    }
}